<template>
  <div class="recommend" ref="recommend">
    <scroll class="recommend-content" ref="scroll" :data="disList">
      <div>
        <div v-if="swiperList.length" class="slider-wrapper">
          <div class="slider-content">  
            <slider ref="slider">
              <div v-for="item in swiperList" :key="item.id">
                <a :href="item.linkUrl">
                  <img :src="item.picUrl" @load="loadImage">
                </a>
              </div>
            </slider>
          </div>
        </div>
          <div class="recommend-list">
            <h1 class="list-title">热门歌单推荐</h1>
            <ul class="music-list">
              <li  class="item" v-for="item in disList" :key="item.content_id">
                <div class="icon">
                  <img v-lazy="item.cover" alt="">
                </div>
                <div class="text">
                  <h1 class="name">{{item.username}}</h1>
                  <p class="desc">{{item.title}}</p>
                </div>
              </li>
            </ul>
          </div>
          <div class="loading-container" v-show="!disList.length">
            <loading />
          </div>
        </div>
      </scroll>
    </div>
</template>

<script>
import Slider from '../../components/slide/Slide'
import { getRecommend, getHotRecommend } from '../../network/recommend'
import { ERR_OK } from '../../network/config'
import Scroll from '../../components/scroll/Scroll'
import Loading from '../../components/loading/Loading'
export default {
  name: 'recommend',
  data () {
    return {
      swiperList: [],
      disList: []
    }
  },
  components: {
    Slider,
    Scroll,
    Loading
  },
  created () {
    this._getRecommend()
    this._getHotRecommend()
  },
  methods: {
    _getRecommend () {
      getRecommend().then(res => {
        if (res.code === ERR_OK) {
          console.log(res.data.sliderList)
          this.swiperList = res.data.sliderList
        }
      })
    },
    _getHotRecommend () {
      getHotRecommend().then(res => {
        if (res.code === ERR_OK) {
          console.log(res.recomPlaylist.data)
          this.disList = res.recomPlaylist.data.v_hot
        }
      })
    },
    loadImage () {
      if (!this.checkloaded) {
        this.checkloaded = true
        setTimeout(() => {
          this.$refs.scroll.refresh()
        }, 20)
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
@import '~@/assets/stylus/variable'
.recommend
  position: fixed
  width: 100%
  top: 88px
  bottom: 0
  .recommend-content
    height: 100%
    overflow: hidden
    .slider-wrapper
      position: relative
      width: 100%
      height: 0
      padding-top: 40%
      overflow: hidden
      .slider-content
        position: absolute
        top: 0
        left: 0
        width: 100%
        height: 100%
  .recommend-list
    .list-title
      height: 65px
      line-height: 65px
      text-align: center
      font-size: $font-size-medium
      color: $color-theme
    .item
      display: flex;
      box-sizing: border-box
      align-items: center
      padding: 0 20px 20px 20px
      .icon
        flex: 0 0 60px
        width: 60px
        padding-right: 20px
        img
          width: 60px
          height: 60px
      .text
        flex: 1
        display: flex
        flex-direction: column
        justify-content: center
        line-height: 20px
        overflow: hidden
        font-size: $font-size-medium
        .name
          margin-bottom: 10px
          color: $color-text
        .desc
          color: $color-text-d
  .loading-container
    position: absolute
    top: 50%
    transform: translateY(-50%)
    width: 100%
</style>
